package com.miaoxun.web.shiro;


import com.miaoxun.domain.entity.User;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

public class ShiroUtils {
    public static Subject getSubjct() {
        return SecurityUtils.getSubject();
    }

    public static User getUser() {
        if (getSubjct() == null)
            return null;
        if (getSubjct().getPrincipal() == null)
            return null;
        if (getSubjct().getPrincipal() instanceof User)
            return (User) getSubjct().getPrincipal();
        else
            return null;
    }

    public static Long getUserId() {
        if (getUser() == null)
            return null;
        return getUser().getUserId();
    }

    public static void logout() {
        if (getSubjct() != null)
            getSubjct().logout();
    }
}
